package thread;

class SingletonLazy{
    private volatile static SingletonLazy  instance = null; // volatile让操作系统每次都是从内存中拿值
    private static Object locker = new Object();

    public static SingletonLazy getInstance(){
        if(instance == null) {
            synchronized (locker) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }
    private SingletonLazy(){

    }
}
public class Demo21 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getInstance();
        SingletonLazy s2 = SingletonLazy.getInstance();
        System.out.println(s1 == s2);
    }
}
